const usersql = require("../../db/sql/usersql")
const md5 = require("md5")

/**
 * 用户登录
 */
export const getLogin = async(ctx, next) => {
    let { userName, userPass } = ctx.request.body
    userPass = md5(userPass)
    try {
        const [isLogin] = await usersql.userLogin([userName, userPass])
        if (isLogin) {
            ctx.body = "登录成功"
        } else {
            ctx.body = "登录失败，用户名或密码错误"
        }
    } catch (error) {
        console.log(error);
    }
};
/**
 * 用户注册
 */
export const register = async(ctx, next) => {
    let res = ctx.request.body
    res.userPass = md5(res.userPass)
    try {
        const [isLogin] = await usersql.userLogin(res)
        if (isLogin) {
            ctx.body = "注册成功"
        } else {
            ctx.body = "登录失败，用户名或密码错误"
        }
    } catch (error) {
        console.log(error);
    }
}